package com.macro.mall.tiny.modules.pms.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.macro.mall.tiny.common.api.CommonResult;
import com.macro.mall.tiny.modules.pms.model.PmsCalculator;
import com.macro.mall.tiny.modules.pms.service.PmsCalculatorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 计算器 前端控制器
 * </p>
 *
 * @author tyrone
 * @since 2024-10-31
 */
@RestController
@RequestMapping("/pms/pmsCalculator")
@Api(tags = "PmsCalculatorController")
@Tag(name = "PmsCalculatorController", description = "计算器列表控制")
public class PmsCalculatorController {

    @Autowired
    private PmsCalculatorService pmsCalculatorService;

    @ApiOperation("万能分页查询 支持show_status type name")
    @PostMapping("/list")
    public CommonResult<IPage<PmsCalculator>> list(@RequestBody PmsCalculator pmsCalculator) {
        QueryWrapper<PmsCalculator> query = new QueryWrapper<>();
        if (pmsCalculator.getShowStatus() != null) {
            query.eq("show_status", pmsCalculator.getShowStatus());
        }
        if (pmsCalculator.getType() != null) {
            query.eq("type", pmsCalculator.getType());
        }
        if (pmsCalculator.getName() != null) {
            query.like("name", pmsCalculator.getName());
        }

        return CommonResult.success(pmsCalculatorService.page(new Page<>(pmsCalculator.getPageNum(), pmsCalculator.getPageSize()),query));
    }

    @ApiOperation("更新计算器信息")
    @PostMapping("/update/{id}")
    public CommonResult<Void> update(@PathVariable Integer id, @RequestBody PmsCalculator pmsCalculator) {
        pmsCalculator.setId(id);
        pmsCalculatorService.updateById(pmsCalculator);
        return CommonResult.success(null);
    }

}

